#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int balancedStringSplit(string s)
    {
        int count = 0;
        int L = 0, R = 0;
        for (int i = 0; i < s.size(); ++i)
        {
            if (s[i] == 'L')
            {
                ++L;
            }
            else
            {
                ++R;
            }
            if (L == R && L != 0)
            {
                ++count;
                L = R = 0;
            }
        }
        return count;
    }
};